<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"></c:set>

<%@ include file="../layout/header.jsp"%>
<div class="container" style="margin-top:50px;">
	<div class="row">
		<h1>角色管理</h1>	
		<div style="margin:10px auto;">
 			<a type="button" class="btn btn-success" href="${ctx}/role/addrole.jsp">新增</a>		
 			<a type="button" id="btnDeleteByIds" class="btn btn-danger" href="#" onclick="return deleteByIds();">删除</a>
 		</div>		
 		<table class="table table-hover table-bordered">
			<tr>					
				<th><input type="checkbox" id="selectAll"></th>
				<th>角色编号</th>
				<th>角色名称</th>
				<th>角色描述</th>
				<th>操作</th>
			</tr>
			<c:forEach var="obj" items="${roles}">
				<tr>					
					<td>
						<c:if test="${obj.id > 1}">
							<input type="checkbox" name="selectOne" value="${obj.id}">
						</c:if>
					</td>
					<td>${obj.id}</td>
					<td>${obj.roleName }</td>
					<td>${obj.description}</td>
					<td>
						<c:if test="${obj.id > 1}">
							<a class="btn btn-danger btn-sm" href="${ctx}/role.do?type=delete&id=${obj.id}" onclick="return confirm('确定要删除选中的记录吗？')">删除</a>
							<a class="btn btn-info btn-sm" href="${ctx}/role.do?type=get&id=${obj.id}" >编辑</a>
						</c:if>
					</td>
				</tr>
			</c:forEach>			
		</table>
 	</div>    	
 </div>
<%@ include file="../layout/footer.jsp"%>
<script type="text/javascript">
	
	function deleteByIds(){
		var flag = true;
		var id_array = new Array();
		$("input[name=selectOne]:checked").each(function(){
			id_array.push($(this).val());
		})
		if(id_array.lenght == 0){
			alert("请至少选择一条记录！");
			flag = false;
		}else{
			//将数组变成字符串 1,2,3
			var ids = id_array.join(",");
			var href="${ctx}/role.do?type=deleteByIds&ids=1" + ids;
			$("#btnDeleteByIds").prop("href",href);			
		}
		return flag;		
	}	
	
	$(function(){
		$("#selectAll").click(function(){
			$("input[name=selectOne]").each(function(){
				$(this).prop("checked",!$(this).prop("checked"))
			})
		})
	})
	
</script>































    
    
    
    
    